/* 
 * File:   Filesystem.h
 * Author: pkv
 *
 * Created on August 4, 2011, 3:37 PM
 * 
 * Implements file handling and loading, primarily backed by physfs.
 */

#ifndef FILESYSTEM_H
#define	FILESYSTEM_H

#include "Lock.h"
#include "Mutex.h"

#include <SLB3/slb.h>
#include <vector>
#include <string>
#include <memory>

class Filesystem
{
public:
    Filesystem();
    ~Filesystem();
    std::string getPathSeparator();
    void useSymbolicLinks(bool allow);
    std::string getBaseDir();
    std::string getUserDir();
    std::string getWriteDir();
    int setWriteDir(std::string newDir);
    int mount(std::string newDir, std::string mountPoint = "", bool appendToPath = false);
    int unmount(std::string oldDir);
    std::vector<std::string> getSearchPath();
    int setSaneConfig(std::string organization, std::string appName, std::string archiveExt, int includeCdRoms, int archivesFirst);
    int mkdir(std::string dirName);
    int del(std::string filename);
    std::string getPath(std::string filename);
    std::vector<std::string> enumerateFiles(std::string dir);
    int exists(std::string filename);
    bool isDirectory(std::string filename);
    bool isSymbolicLink(std::string filename);
    std::auto_ptr<std::ostream> openWrite(std::string filename, bool append = false);
    std::auto_ptr<std::istream> openRead(std::string filename);
    std::string openTemp(std::string filename);
    // TODO: do i need a way to close files?
    // TODO: add special SLB augmented file types

private:
    static Mutex _mutex;
    static int _numInstances;
};

SLB3_DECLARATION(Filesystem, "plinth.Filesystem", policy::Default);

#endif	/* FILESYSTEM_H */

